<?php
/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return
 *   A string containing the breadcrumb output.
 */
function hkfanr_theme_breadcrumb($variables){
  $breadcrumb = $variables['breadcrumb'];
  $breadcrumb_separator=theme_get_setting('breadcrumb_separator','hkfanr_theme');
  
  $show_breadcrumb_home = theme_get_setting('breadcrumb_home');
  if (!$show_breadcrumb_home) {
  array_shift($breadcrumb);
  }
  
  if (!empty($breadcrumb)) {
    $breadcrumb[] = drupal_get_title();
    return '<div class="breadcrumb">' . implode(' <span class="breadcrumb-separator">' . $breadcrumb_separator . '</span>', $breadcrumb) . '</div>';
  }
}

function hkfanr_theme_page_alter($page) {

	if (theme_get_setting('responsive_meta','hkfanr_theme')):
	$mobileoptimized = array(
		'#type' => 'html_tag',
		'#tag' => 'meta',
		'#attributes' => array(
		'name' =>  'MobileOptimized',
		'content' =>  'width'
		)
	);

	$handheldfriendly = array(
		'#type' => 'html_tag',
		'#tag' => 'meta',
		'#attributes' => array(
		'name' =>  'HandheldFriendly',
		'content' =>  'true'
		)
	);

	$viewport = array(
		'#type' => 'html_tag',
		'#tag' => 'meta',
		'#attributes' => array(
		'name' =>  'viewport',
		'content' =>  'width=device-width, initial-scale=1'
		)
	);
	
	drupal_add_html_head($mobileoptimized, 'MobileOptimized');
	drupal_add_html_head($handheldfriendly, 'HandheldFriendly');
	drupal_add_html_head($viewport, 'viewport');
	endif;
	
}

function hkfanr_theme_preprocess_html(&$variables) {

	if (!theme_get_setting('responsive_respond','hkfanr_theme')):
	drupal_add_css(path_to_theme() . '/css/basic-layout.css', array('group' => CSS_THEME, 'browsers' => array('IE' => '(lte IE 8)&(!IEMobile)', '!IE' => FALSE), 'preprocess' => FALSE));
	endif;
	
	drupal_add_css(path_to_theme() . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => '(lte IE 8)&(!IEMobile)', '!IE' => FALSE), 'preprocess' => FALSE));
}

/**
 * Override or insert variables into the html template.
 */
function hkfanr_theme_process_html(&$vars) {
	// Hook into color.module
	if (module_exists('color')) {
	_color_html_alter($vars);
	}

}

/**
 * Override or insert variables into the page template.
 */
function hkfanr_theme_process_page(&$variables) {
  // Hook into color.module.
  if (module_exists('color')) {
    _color_page_alter($variables);
  }
 
}
function hkfanr_theme_preprocess_page(&$vars) {
    // custom content type page template
    // Renders a new page template to the list of templates used if it exists
    if (isset($vars['node']->type)) {
    // This code looks for any page--custom_content_type.tpl.php page
        $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
    }
}
function hkfanr_theme_form_alter(&$form, &$form_state, $form_id) {
    if($form_id=='article_node_form'){
        //drupal_add_js(drupal_get_path('theme', 'hkfanr_theme') . '/js/form_formate.js');
        //drupal_add_js('form_format_article_add();', 'inline');
        //drupal_add_js('jQuery(document).ready(function () { form_format_article_add(); });', 'inline');
    }
    if ($form_id == 'search_block_form') {
        unset($form['search_block_form']['#title']);
        $form['search_block_form']['#title_display'] = 'invisible';
        $form_default = t('Search');
        $form['search_block_form']['#default_value'] = $form_default;
        $form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/search-button.png');
        $form['search_block_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = '{$form_default}';}", 'onfocus' => "if (this.value == '{$form_default}') {this.value = '';}" );
    }
}
/**
 * Implemention hook_theme
 */
function hkfanr_theme_theme() {
    $theme = array(
        'ad720x90' => array(
            'path' => drupal_get_path('theme', 'hkfanr_theme') . '/ad',
            'template' => '720x90',
        ),
        'ad300x250' => array(
            'path' => drupal_get_path('theme', 'hkfanr_theme') . '/ad',
            'template' => '300x250',
        ),
        'right_bar_button' => array(
            'template' => 'right-bar-button',
            'path' => drupal_get_path('theme', 'hkfanr_theme') . '/templates',
            'variables' => array(
                'node_type' => NULL,
                'list_type' => NULL,
            ),
        ),
    );
    return $theme;
}


/**
 * Add javascript files for jquery slideshow.
 */
drupal_add_js(drupal_get_path('theme', 'hkfanr_theme') . '/js/form_formate.js');
drupal_add_js(drupal_get_path('theme', 'hkfanr_theme') . '/js/menu.js');
drupal_add_js(drupal_get_path('theme', 'hkfanr_theme') . '/js/jquery.cycle.all.js');
drupal_add_js(drupal_get_path('theme', 'hkfanr_theme') . '/js/jquery.rotate.js');
//drupal_add_css(path_to_theme() . '/css/content_type.css');
?>